package cn.cqautotest.cqviehelper.utils;

import android.graphics.Color;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class ColorPool {

    private static final List<Integer> colors = new ArrayList<>();
    private static final List<Integer> localColors = new ArrayList<>();

    /**
     * 初始化颜色池
     */
    static {
        colors.add(Color.parseColor("#A1F29B"));
        colors.add(Color.parseColor("#C8FCA2"));
        colors.add(Color.parseColor("#D6E69F"));
        colors.add(Color.parseColor("#FCF9A2"));
        colors.add(Color.parseColor("#F2E79B"));
        colors.add(Color.parseColor("#9CF9A2"));
        colors.add(Color.parseColor("#9BF2DD"));
        colors.add(Color.parseColor("#FCECA2"));
        colors.add(Color.parseColor("#F2CD9B"));
        //colors.add(Color.parseColor("#B4CFFC"));
        //colors.add(Color.parseColor("#9BC2F2"));
        colors.add(Color.parseColor("#F2A79B"));
        colors.add(Color.parseColor("#85F2EC"));
        colors.add(Color.parseColor("#AEFC9D"));
        colors.add(Color.parseColor("#FF66CC"));
        colors.add(Color.parseColor("#F26B57"));
        colors.add(Color.parseColor("#EB57F2"));
        colors.add(Color.parseColor("#FF8C66"));
        colors.add(Color.parseColor("#FF0093"));
    }

    /**
     * 返回一个配色好看的颜色池
     *
     * @return
     */
    public static List<Integer> getColors() {
        return colors;
    }

    /**
     * 随机返回一个配色好看的颜色值与之前获取的不重复
     *
     * @return
     */
    public static int getRandomColor() {
        List<Integer> colors = getColors();
        int nextInt = new Random().nextInt(colors.size());
        int index = 0;
        Integer colorVale;
        do {
            colorVale = colors.get(nextInt);
            if (index >= colors.size()) {
                return colorVale;
            }
            index++;
        } while (localColors.contains(colorVale));
        localColors.add(colorVale);
        return colorVale;
    }
}
